package com.njwb.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.njwb.constant.Code;
import com.njwb.json.Result;
import com.njwb.pojo.User;
import com.njwb.service.UserService;
import com.njwb.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("user/login")
    public Result login(User user){
        return userService.login(user);
    }

    @RequestMapping("user/updatePwd")
    public Result updatePwd(@RequestHeader(value = "Authorization") String token){
        Result result = new Result();
        result.setCode(Code.SUCCESS);
        result.setCodeMsg(Code.SUCCESS_MSG);
        System.out.println(token);
        return result;
//        //获取的token格式为
//        //Bearer x.y.z
//        token = token.split("\\s+")[1];//没有token的格式  Bearer  null
//        if("null".equals(token)){
//            //未登录
//            result.setCode(Code.AUTH_ERROR);
//            result.setCodeMsg(Code.AUTH_ERROR_MSG);
//        }else{
//            try{
//                DecodedJWT decodedJWT = JWTUtil.verfiyJWT(token);
//                System.out.println(JWTUtil.getPayload("userId",token));
//                System.out.println(JWTUtil.getPayload("account",token));
//                result.setCode(Code.SUCCESS);
//                result.setCodeMsg(Code.SUCCESS_MSG);
//            }catch (Exception e){
//                //鉴权不通过
//                result.setCode(Code.AUTH_ERROR);
//                result.setCodeMsg(Code.AUTH_ERROR_MSG);
//            }
//        }

    }
}
